package commRedisRpc

import (
	"encoding/json"
	commRedisRpc "gitee.com/fierce_wolf/go-fox-edge-common/commRedisList"
	"time"
)

type redisListChannelServerRequest struct {
	channelType string
	redisList   commRedisRpc.RedisListService
}

func (e *redisListChannelServerRequest) Pop(channelType string, timeout time.Duration) (*ChannelRequestVO, error) {
	mainKey := "fox.edge.list:channel:" + channelType + ":request"

	jsn, err := e.redisList.KBPop(mainKey, timeout)
	if err != nil {
		return nil, err
	}
	if jsn == "" {
		return nil, err
	}

	var vo ChannelRequestVO
	err = json.Unmarshal([]byte(jsn), &vo)
	if err != nil {
		return nil, err
	}

	return &vo, nil
}
